//
//  RCVoiceSelectView.swift
//  RunChuanThermometer
//
//  Created by 李东 on 2024/4/18.
//

import UIKit
import SnapKit

class RCVoiceSelectView: UIView {
    
    lazy var leftBtn = UIButton(type: .custom)
    lazy var leftLine = UIImageView(image: UIImage(named: "icon_line_long"))
    lazy var rightBtn = UIButton(type: .custom)
    lazy var rightLine = UIImageView(image: UIImage(named: "icon_line_short"))
    
    var selectCallBack:((Bool) ->Void)?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        leftBtn.titleLabel?.font = UIFont.Medium(ofSize: 18)
        leftBtn.setTitleColor(.white, for: .normal)
        leftBtn.setTitle("趣味音效", for: .normal)
        leftBtn.addTarget(self, action: #selector(itemBtnHandle(sender:)), for: .touchUpInside)
        addSubview(leftBtn)
        leftBtn.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.right.equalTo(self.snp.centerX)
        }
        
        insertSubview(leftLine, belowSubview: leftBtn)
        leftLine.snp.makeConstraints { make in
            make.centerX.equalTo(leftBtn)
            make.bottom.equalToSuperview().offset(-10)
        }
        
        rightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        rightBtn.setTitleColor(.white, for: .normal)
        rightBtn.setTitle("动物", for: .normal)
        rightBtn.addTarget(self, action: #selector(itemBtnHandle(sender:)), for: .touchUpInside)
        addSubview(rightBtn)
        rightBtn.snp.makeConstraints { make in
            make.right.top.bottom.equalToSuperview()
            make.left.equalTo(self.snp.centerX)
        }
        rightLine.isHidden = true
        insertSubview(rightLine, belowSubview: rightBtn)
        rightLine.snp.makeConstraints { make in
            make.centerX.equalTo(rightBtn)
            make.bottom.equalToSuperview().offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func itemBtnHandle(sender: UIButton) {
        if sender == leftBtn {
            leftLine.isHidden = false
            rightLine.isHidden = true
            leftBtn.titleLabel?.font = UIFont.Medium(ofSize: 18)
            rightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }else {
            leftLine.isHidden = true
            rightLine.isHidden = false
            rightBtn.titleLabel?.font = UIFont.Medium(ofSize: 18)
            leftBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }
        selectCallBack?(sender == leftBtn)
    }
    
}
